<?php

namespace app\api\controller\v1;

use think\facade\Filesystem;
use app\common\service\ApiReturn;
use app\api\controller\Base;
use app\common\service\UploadService;

class Upload extends Base
{
    /** 
     * @Author: Bryant 
     * @Date: 2023-06-07 15:47:42 
     * @method post 
     * @title 图片上传 
     */
    public function image($data = [], $user = [])
    {
        $file = request()->file('file');
        try {
            $upload_service = new UploadService();
            $upload_service->validateException($file);

            $result = $upload_service->save($file);
        } catch (\Exception $e) {
            return ApiReturn::r(0, [], $e->getMessage());
        }

        return ApiReturn::r(1,  $result, '上传成功');
    }
}
